#include "DeviceCaptureAndSendAd.h"
#include "CapturExports.h"

#include <stdexcept>

DeviceCaptureAndSendAd::DeviceCaptureAndSendAd(const wchar_t* deviceFriendlyName)
{
	m_RealObject = CreateDeviceCaptureAndSend(deviceFriendlyName);
	if (m_RealObject == NULL)
	{
		throw std::runtime_error("Create deivce capture and send error");
	}
}

DeviceCaptureAndSendAd::~DeviceCaptureAndSendAd()
{
	DeviceCaptureAndSendDelete( m_RealObject );
}

bool DeviceCaptureAndSendAd::start()
{
	return DeviceCaptureAndSendStart(m_RealObject);
}

bool DeviceCaptureAndSendAd::pause()
{
	return DeviceCaptureAndSendPause(m_RealObject);
}

bool DeviceCaptureAndSendAd::stop()
{
	return DeviceCaptureAndSendStop(m_RealObject);
}

bool DeviceCaptureAndSendAd::addVideoSocket(int socket)
{
	return DeviceCaptureAndSendAddVideoSocket(m_RealObject,socket);
}

bool DeviceCaptureAndSendAd::addAudioSocket(int socket)
{
	return DeviceCaptureAndSendAddAudioSocket(m_RealObject,socket);
}

bool DeviceCaptureAndSendAd::clearAllSocket()
{
	return DeviceCaptureAndSendClearAllSocket(m_RealObject);
}

bool DeviceCaptureAndSendAd::getPreviewWindowSize(long* width,long* height)
{
	return DeviceCaptureAndSendGetPreviewSize(m_RealObject, width, height);
}

bool DeviceCaptureAndSendAd::setPreviewParent(HANDLE parent)
{
	return DeviceCaptureAndSendSetPreivewParent(m_RealObject, parent);
}

bool DeviceCaptureAndSendAd::resetDevice(const wchar_t* deviceName)
{
	return DeviceCaptureAndSendResetDevice(m_RealObject, deviceName);
}

bool DeviceCaptureAndSendAd::getInputVideoPinNames(std::vector<std::wstring>& resultList)
{
	int count = 10;
	int maxSize = 100;
	wchar_t *deviceNameList[10];
	int newCount = count;
	for (int i = 0; i <count; ++i)
	{
		deviceNameList[i] = new wchar_t[maxSize];
	}
	if (!DeviceCaptureAndSendGetInputVideoPinNames(m_RealObject, deviceNameList, &newCount, maxSize))
	{
		for (int i = 0; i <count; ++i)
		{
			delete[] deviceNameList[i];
		}
		return false;
	}

	for (int i = 0; i < newCount; ++i)
	{
		resultList.push_back(deviceNameList[i]);
	}

	for (int i = 0; i <count; ++i)
	{
		delete[] deviceNameList[i];
	}

	return true;
}

bool DeviceCaptureAndSendAd::setVideoInputPin(int intputIndex)
{
	return DeviceCaptureAndSendSetVideoInputPin(m_RealObject, intputIndex);
}